package com.xiaoyu.merchant.ui.activity.wallet;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.EditText;

import com.xiaoyu.commonlib.network.CommonHttpResponser;
import com.xiaoyu.commonlib.ui.base.BaseActivityWithTitle;
import com.xiaoyu.commonlib.utils.PreferencesUtil;
import com.xiaoyu.commonlib.utils.ToastUtil;
import com.xiaoyu.merchant.R;
import com.xiaoyu.merchant.network.NetworkManager;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class BankCardActivity extends BaseActivityWithTitle {

    @BindView(R.id.bank_card_name_edit)
    EditText mCardName;
    @BindView(R.id.bank_card_num_edit)
    EditText mCardNumber;
    @BindView(R.id.bank_card_confirm_num_edit)
    EditText mConfirmCardNum;
    @BindView(R.id.bank_card_edit)
    EditText mBankname;
    @BindView(R.id.bank_card_set_pwd_edit)
    EditText mExtractpassword;
    @BindView(R.id.bank_card_confirm_pwd_edit)
    EditText mConfirmPwd;

    @Override
    protected void loadContentView(ViewGroup parent) {
        setTitleText("绑定银行卡");
        LayoutInflater.from(this).inflate(R.layout.activity_bank_card, parent, true);
        ButterKnife.bind(this);
    }

    //提交
    @OnClick(R.id.bank_card_submit)
    public void submitClick() {
        if (TextUtils.isEmpty(mCardName.getText().toString()) || TextUtils.isEmpty(mCardNumber.getText().toString())
                || TextUtils.isEmpty(mConfirmCardNum.getText().toString()) || TextUtils.isEmpty(mBankname.getText().toString())
                || TextUtils.isEmpty(mExtractpassword.getText().toString()) || TextUtils.isEmpty(mConfirmPwd.getText().toString())) {
            ToastUtil.showToast(this, "请输入内容");
            return;
        }
        getBindBankCard();
    }

    //绑定银行卡
    private void getBindBankCard() {
        NetworkManager.submitBindCard(PreferencesUtil.getString(PreferencesUtil.TOKEN, ""), mCardNumber.getText().toString(),
                mBankname.getText().toString(), mCardName.getText().toString(), mExtractpassword.getText().toString(), new CommonHttpResponser() {
                    @Override
                    public void onSuccess(String result) {
                        PreferencesUtil.commit(PreferencesUtil.PAY_PWD, mExtractpassword.getText().toString());
                        ToastUtil.showToast(BankCardActivity.this, "绑定银行卡成功");
                        finish();
                    }

                    @Override
                    public void onFailed(String errorCode, String errorDiscription) {

                    }
                });
    }
}
